<?php
declare(strict_types=1);

namespace App\Resource\Activity\LaborDay2023;


use Illuminate\Http\Resources\Json\JsonResource;

class LeaderboardResource extends JsonResource
{
    public function toArray($request): array
    {

        list($diff, $decimal) =  explode('.', (string)$this->diff);
        $diff = preg_replace('/(?<=[0-9])(?=(?:[0-9]{3})+(?![0-9]))/', ',',$diff);
        if ($decimal)$diff .= '.'. $decimal;

        return [
            // "id" => $this->id,
            "user_id" => $this->user_id,
            "ranking" => $this->ranking,
            "count" => $this->count,
            "room_id" => $this->room->room_id ?? 0,
            "diff" => $diff,
            "user" => UserResource::make($this->user),
        ];
    }
}